Two-photon laser-scanning microscopy (TPLSM) is a critical tool for basic and biomedical neurobiology. It uniquely allows three-dimensional imaging deep within intact brain tissue and at high resolutions. TPLSM in vivo has enabled ground-breaking studies of normal brain function and disorders of the brain, including stroke, traumatic brain injury, epilepsy, Alzheimer's disease, Parkinson's disease, and spinal cord injury. Recently, TPLSM has been applied to behaving animals, creating a new experimental paradigm where detailed maps of cellular brain activity can be directly correlated with measured behavior. TPLSM is also compatible with optogenetics, allowing photostimulation of targeted neurons. ScanImage is standalone open-source software for controlling TPLSM experiments that has been at the forefront of TPLSM applications for neurobiology. ScanImage has been adopted by over 200 labs (and counting). ScanImage controls, home-built and commercial microscope hardware and entire neurophysiology experiments. Vidrio Technologies has been formed to meet strong and widespread demand for commercial support and development service for ScanImage. The demand vastly exceeds what a single laboratory can provide and is expected to grow further, with multiple large research institutes and President Obama's BRAIN Initiative identifying cellular resolution imaging in behaving subjects as a high-priority research area. We will rework ScanImage into robust commercial software that supports customization. The new software will support closed-loop TPLSM: Image acquisition, image analysis and stimulus generation are each inserted into a processing loop. The stimuli can be behavioral or can involve optogenetics. The closed-loop paradigm will allow investigators to establish causality, not just correlation, between brain activity and behavior. In Phase 1, Vidrio will create ScanImage 5, demonstrating the feasibility of flexible software to power closed-loop TPLSM experiments. Vidrio will (1) Unify resonant and galvanometer laser scanning mode - for fast TPLSM imaging and optogenetic photostimulation of targeted cells, respectively - into a single package; (2) demonstrate an architecture allowing custom scripted central processing unit (CPU) computation to implement closed-loop experiments; and (3) demonstrate a platform supporting custom low-level field-programmable-gate array (FPGA) computation to implement real-time, low latency closed-loop experiments. Phase 2 will build on these features to implement powerful new tools for interrogating brain function in behaving animals, including: real-time motion correction, 3d photostimulation, adaptive sampling for mapping activity in 3d. These features will provide a solution and product for precise and powerful inferential studies of brain activity and behavior.